var t = require("../../@babel/runtime/helpers/createForOfIteratorHelper"),
  a = require("../../utils/http.js"),
  e = require("../../utils/api.js"),
  i = require("../../utils/language/switchLanguage.js");
Page({
  data: {
    navlist: ["单位开票", "个人开票"],
    currentTab: 0,
    name: "",
    Acount: "",
    Email: "",
    isShow: !1,
    suggestionList: [],
    isShowList: !1,
  },
  onLoad: function (t) {
    var a = wx.getStorageSync("chooseId");
    this.initLanguage(),
      this.setData({
        orderSn: a ? a.join(",") : "",
        totalPrice: t.totalPrice,
        id: t.id,
        from: t.from,
      });
  },
  initLanguage: function () {
    var t = i.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: t, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: t["开取发票"] });
  },
  openMore: function () {
    this.setData({ isShow: !this.data.isShow });
  },
  chooseNav: function (t) {
    var a = t.currentTarget.dataset.idx;
    this.setData({ currentTab: a });
  },
  querySearch: function (e) {
    var i = this;
    a.getCompanyName(e).then(function (a) {
      var e,
        n = a.data,
        s = [],
        o = t(n);
      try {
        for (o.s(); !(e = o.n()).done; ) {
          var c = e.value;
          s.push({ value: c.name, code: c.code });
        }
      } catch (t) {
        o.e(t);
      } finally {
        o.f();
      }
      i.setData({ suggestionList: s, isShowList: !0 });
    });
  },
  getCompanyCode: function (t) {
    var e = this;
    a.getCompanyCode(t).then(function (t) {
      e.setData({ Acount: t.data.kpCode });
    });
  },
  handleSelect: function (t) {
    var a = t.currentTarget.dataset.idx;
    this.setData({ name: this.data.suggestionList[a].value, isShowList: !1 }),
      this.getCompanyCode({ code: this.data.suggestionList[a].code });
  },
  resetOpenInvoice: function () {
    var t = this;
    if ("" != this.data.name)
      if ("" != this.data.Email) {
        var i = {
          invoiceClassify: this.data.currentTab,
          invoiceHeader: this.data.name,
          invoiceType: 0,
          companyTaxNumber: this.data.Acount,
          bankAccount: this.data.Account,
          companyAddress: this.data.Address,
          companyMobile: this.data.Mobile,
          bankName: this.data.Bank,
          email: this.data.Email,
          invoiceContent: this.data.Remark,
          id: this.data.id,
        };
        wx.showModal({
          title: this.data._t["提示"],
          content: this.data._t["是否确认提交？"],
          confirmText: t.data._t["确定"],
          cancelText: t.data._t["取消"],
          success: function (n) {
            n.confirm &&
              a.resetOpenInvoice(i).then(function (a) {
                e.showMsg(t.data._t["提交成功"]);
                var i = getCurrentPages(),
                  n = "";
                "index" == t.data.from
                  ? (n = i[i.length - 2])
                  : "info" == t.data.from && (n = i[i.length - 3]),
                  n.setData({ refresh: !0, currentTab: 1 }, function () {
                    n.getInvoiceList({ page: 1, limit: 15 });
                  }),
                  wx.navigateBack();
              });
          },
        });
      } else e.showMsg(this.data._t["请填写接收邮箱"]);
    else e.showMsg(this.data._t["请填写发票抬头"]);
  },
  SaveInvoiceOrder: function () {
    var t = this;
    if ("" != this.data.name)
      if ("" != this.data.Email) {
        var i = {
          invoiceClassify: this.data.currentTab,
          invoiceHeader: this.data.name,
          invoiceType: 0,
          orderSn: this.data.orderSn,
          companyTaxNumber: this.data.Acount,
          bankAccount: this.data.Account,
          companyAddress: this.data.Address,
          companyMobile: this.data.Mobile,
          bankName: this.data.Bank,
          email: this.data.Email,
          invoiceContent: this.data.Remark,
        };
        wx.showModal({
          title: this.data._t["提示"],
          content: this.data._t["是否确认提交？"],
          confirmText: this.data._t["确定"],
          cancelText: this.data._t["取消"],
          success: function (n) {
            n.confirm &&
              a.SaveInvoiceOrder(i).then(function (a) {
                e.showMsg(t.data._t["提交成功"]);
                var i = getCurrentPages(),
                  n = i[i.length - 2];
                n.setData({ refresh: !0 }, function () {
                  n.getInvoiceList({ page: 1, limit: 15 });
                }),
                  wx.navigateBack();
              });
          },
        });
      } else e.showMsg(this.data._t["请填写接收邮箱"]);
    else e.showMsg(this.data._t["请填写发票抬头"]);
  },
  getName: function (t) {
    this.setData({ name: t.detail.value }),
      0 == this.data.currentTab &&
        t.detail.value.length > 3 &&
        this.querySearch({ name: t.detail.value });
  },
  getEmail: function (t) {
    this.setData({ Email: t.detail.value });
  },
  getAcount: function (t) {
    this.setData({ Acount: t.detail.value });
  },
  getAddress: function (t) {
    this.setData({ Address: t.detail.value });
  },
  getMobile: function (t) {
    this.setData({ Mobile: t.detail.value });
  },
  getBank: function (t) {
    this.setData({ Bank: t.detail.value });
  },
  getAccount: function (t) {
    this.setData({ Account: t.detail.value });
  },
  getRemark: function (t) {
    this.setData({ Remark: t.detail.value });
  },
  toPage: function () {
    wx.navigateTo({ url: "/pages/invoiceing/index" });
  },
  CallPhone: function () {
    wx.makePhoneCall({ phoneNumber: wx.getStorageSync("telphoneNumber") });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {
    wx.removeStorageSync("chooseId");
  },
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
